<!-- Modal -->
<div class="modal-dialog wide" style="width: 550px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">
            <#if codeInfo??>
                <#if codeInfo.id??>
                    编辑
                <#else>
                    新增
                </#if>
            </#if>
            </h4>
        </div>
        <div class="modal-body">
            <div id="errorMessage"><#include "../../message.ftl" /></div>
            <form class="form-horizontal" role="form" id="codeInfoForm" method="post"
                  action="${absoluteContextPath}/system/codeInfo/save">
            <#if codeInfo??>
                <#if codeInfo.id??>
                    <input type="hidden" name="id" value="${codeInfo.id}"/>
                <#else>
                    <input type="hidden" name="id" value=""/>
                </#if>
            </#if>

                <div class="row">
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">代码类别ID</label>

                        <div class="col-sm-6">
                            <input name="codeTypeId" id="codeTypeId" value="${codeInfo.codeTypeId!''}" type="text"
                                   class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">代码信息值<sup style="color: red">*</sup></label>

                        <div class="col-sm-6">
                            <input name="value" value="${codeInfo.value!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">代码信息内容 <sup style="color: red">*</sup></label>

                        <div class="col-sm-6">
                            <input name="content" value="${codeInfo.content!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">上级类型</label>

                        <div class="col-sm-6">
                        <#include "selectType.ftl" />
                        </div>
                    </div>
                <#if codeInfo.parentValue?? && codeInfo.parentValue != "">
                <div class="form-group col-md-12" id="parentCodeInfoValue">
                <#else>
                <div class="form-group col-md-12" id="parentCodeInfoValue" style="display: none">
                </#if>
                    <label class="col-sm-4 control-label">上级联动值</label>

                    <div class="col-sm-6" id="parentValue">
                    <#include "selectCodeTypeValue.ftl" />
                    </div>
                </div>

                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">排序号</label>

                        <div class="col-sm-6">
                            <input name="sortNo" value="${codeInfo.sortNo!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button type="button" class="btn btn-primary" onclick="save();">保存</button>
        </div>
    </div>
</div>
<script>

    $(function () {
        var codeTypeId = $("#codeTypeId").val();
        if (codeTypeId) {
            $("#codeTypeId").attr("readonly", "readonly");
        } else {
            var selectTypeId = $("#selectTypeId").val();
            $("#codeTypeId").val(selectTypeId);
            $("#codeTypeId").attr("readonly", "readonly");

        }
    });
    function save() {
        var codeTypeId = $("#codeTypeId").val();
        $("#" + "codeInfoForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "代码信息保存成功！", type: "success"});
                    refreshTableInfo(codeTypeId);
                } else {
                    $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：代码" + data.returnMsg, type: "success"});
                }
            }
        });
    }
    function refreshParentValue(codeTypeId) {
        if (codeTypeId != undefined) {
            var data = {};
            var url = '${absoluteContextPath}/system/codeInfo/parentValueList';
            data.codeTypeId = codeTypeId;
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $("#parentValue").html(data.content.data);
                        $("#parentCodeInfoValue").show();
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }
    }
</script>